﻿using System;
using EntitiesTM;
using DataAccess;
using System.Data;

namespace Business
{
    public class BuStaff
    {
        public BuStaff()
        {

        }

        public static int CheckSignIn(string email, string password)
        {
            DaStaff staffExist = new DaStaff();
            int result = 0;
            result = staffExist.checkSignIn(email,password);
            return result;
        }
        public static int[] CheckStaffExists(EnStaff staff)
        {
            DaStaff staffExist = new DaStaff();
            int[] result = {0,0};
            result = staffExist.CheckStaffExists(staff);
            return result;
        }

        public static EnStaff GetStaffByEmailOpt(string email, string companyid)
        {
            DaStaff staffExist = new DaStaff();
            DataRow dtTmp = staffExist.GetStaffByEmailOpt(email, companyid).Rows[0];
            EnStaff staff = new EnStaff();

            staff.staffName = dtTmp["StaffName"].ToString();
            staff.staffPermissionID = Int32.Parse(dtTmp["StaffPermissionID"].ToString());
            staff.permissionName = dtTmp["PermissionName"].ToString();
            return staff;
        }

        public static DataTable selAllStaff(string companyid)
        {
            DaStaff staff = new DaStaff();
            return staff.selAllStaff(companyid);
        }

        public static DataTable selAllStaffOpt(string companyid)
        {
            DaStaff staff = new DaStaff();
            return staff.selAllStaffOpt(companyid);
        }

        public static DataTable selAllStaffOptByResultUnit(string email, string companyid)
        {
            DaStaff staff = new DaStaff();
            return staff.selAllStaffOptByResultUnit(email, companyid);
        }

        public static int selStaffIDByEmail(string email, string companyid)
        {
            DaStaff staff = new DaStaff();
            return Int32.Parse(staff.selStaffIDByEmail(email, companyid).Rows[0][0].ToString());
        }

        public static int selResultUnitIDByEmail(string email, string companyid)
        {
            DaStaff staff = new DaStaff();
            return Int32.Parse(staff.selResultUnitIDByEmail(email, companyid).Rows[0][0].ToString());
        }

        public static EnStaff selStaffByEmail(string email, string companyid)
        {
            DaStaff staffExist = new DaStaff();
            DataRow dtTmp = staffExist.selStaffByEmail(email, companyid).Rows[0];
            EnStaff staff = new EnStaff();
            staff.companyName = dtTmp["CompanyName"].ToString();
            staff.permissionName = dtTmp["PermissionName"].ToString();
            staff.ResultUnitName = dtTmp["ResultUnitName"].ToString();
            staff.staffAddress = dtTmp["StaffAddress"].ToString();
            staff.staffPosition = dtTmp["StaffPosition"].ToString();
            string birthday = dtTmp["StaffBirthday"].ToString();
            if (!birthday.Equals(""))
            {
                staff.staffBirthday = DateTime.Parse(birthday);
            }
            
            staff.staffCompanyID = Int32.Parse(dtTmp["StaffCompanyID"].ToString());
            staff.staffEmail = dtTmp["StaffEmail"].ToString();
            string gender = dtTmp["StaffGender"].ToString();
            if (!gender.Equals(""))
            {
                staff.staffGender = Boolean.Parse(gender);
            }
            string level = dtTmp["StaffLevel"].ToString();
            if (!level.Equals(""))
            {
                staff.staffLevel = Int32.Parse(level);
            }
            staff.staffName = dtTmp["StaffName"].ToString();
            staff.staffPermissionID = Int32.Parse(dtTmp["StaffPermissionID"].ToString());
            staff.staffPhone = dtTmp["StaffPhone"].ToString();
            string result = dtTmp["StaffResultUnitID"].ToString();
            if (!result.Equals(""))
            {
                staff.staffResultUnitID = Int32.Parse(result);
            }
            staff.staffScale = dtTmp["StaffScale"].ToString();
            return staff;
        }

        public static void updStaffOpt(EnStaff staff, string companyid)
        {
            DaStaff staffExist = new DaStaff();
            staffExist.updStaffOpt(staff, companyid);
        }

        public static void resetPass(EnStaff staff, string companyid)
        {
            DaStaff staffExist = new DaStaff();
            staffExist.resetPass(staff, companyid);
        }

        public static void updStaff(EnStaff staff, string companyid)
        {
            DaStaff staffExist = new DaStaff();
            staffExist.updStaff(staff, companyid);
        }

        public static void updMyProfile(EnStaff staff, string companyid)
        {
            DaStaff staffExist = new DaStaff();
            staffExist.updMyProfile(staff, companyid);
        }

        public static void insStaffOpt(EnStaff staff, string companyid)
        {
            DaStaff staffExist = new DaStaff();
            staffExist.insStaffOpt(staff, companyid);
        }

        public static void insStaff(EnStaff staff, string companyid)
        {
            DaStaff staffExist = new DaStaff();
            staffExist.insStaff(staff, companyid);
        }

        public static void delStaff(EnStaff staff, string companyid)
        {
            DaStaff staffExist = new DaStaff();
            staffExist.delSAStaff(staff, companyid);
            staffExist.delSPStaff(staff, companyid);
            staffExist.delStaff(staff, companyid);
        }

        public static int UpdatePassword(EnStaff staff, string passNew, string companyid)
        {
            DaStaff staffExist = new DaStaff();
            return staffExist.UpdatePass(staff, passNew, companyid);
        }

        public static void updLostPassword(EnStaff staff, string companyid)
        {
            DaStaff staffExist = new DaStaff();
            staffExist.updLostPassword(staff, companyid);
        }

        public static int[] checkEmail(string email)
        {
            DaStaff staffExist = new DaStaff();
            int[] result = {0,0};
            result = staffExist.checkEmail(email);
            return result;
        }
    }
}
